using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Text.RegularExpressions;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_TemplateView : Admin, IRequiresSessionState
{
	protected Literal TemplateTitle;
	protected Literal EditTemplateTitle;
	protected Literal TemPath;
	protected Literal TemplateFileName;
	protected TextBox TemplateName;
	protected Literal TemNameMsg;
	protected TextBox TemplateContent;
	protected HtmlForm form1;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.BindPage();
	}
	protected void BindPage()
	{
		string str = this.config["TemplateDir"].ToString().Replace("/", "\\");
		this.TemplateFileName.Visible = true;
		this.TemplateName.Visible = false;
		this.TemNameMsg.Visible = false;
		this.TemPath.Visible = false;
		this.TemplateTitle.Visible = false;
		this.EditTemplateTitle.Visible = true;
		string text = base.Request["Dir"];
		this.TemplateFileName.Text = text;
		string truePath = Fetch.GetTruePath(str + text);
		string text2 = "";
		FileIO fileIO = new FileIO();
		try
		{
			text2 = fileIO.ReadFromFile(truePath);
			text2 = this.ReplaceSysLabel(text2);
		}
		catch (Exception ex)
		{
			this.WriteErrMsg("", Language.GetAdminMsg("Template/ReadTemErr", ex.Message.ToString()), "");
		}
		this.TemplateContent.Text = text2;
	}
	protected string ReplaceSysLabel(string LabelContent)
	{
		SysLabel sysLabel = new SysLabel(this.conn);
		if (LabelContent.Contains("{HL.Config.Logo}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.Logo}", "<!--{HL.Config.Logo}-->" + sysLabel.ShowLogo() + "<!--{HL.Config.Logo/}-->");
		}
		if (LabelContent.Contains("{HL.Config.SiteName}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.SiteName}", "<!--{HL.Config.SiteName}-->" + sysLabel.ShowLogo() + "<!--{HL.Config.SiteName/}-->");
		}
		if (LabelContent.Contains("{HL.Config.InstallDir}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.InstallDir}", "<!--{HL.Config.InstallDir}-->" + sysLabel.ShowInstallDir() + "<!--{HL.Config.InstallDir/}-->");
		}
		if (LabelContent.Contains("{HL.Config.Banner}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.Banner}", "<!--{HL.Config.ShowBanner}-->" + sysLabel.ShowBanner() + "<!--{HL.Config.ShowBanner/}-->");
		}
		if (LabelContent.Contains("{HL.Config.WebMaster}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.WebMaster}", "<!--{HL.Config.WebMaster}-->" + sysLabel.ShowWebMaster() + "<!--{HL.Config.WebMaster/}-->");
		}
		if (LabelContent.Contains("{HL.Config.WebMasterEmail}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.WebMasterEmail}", "<!--{HL.Config.WebMasterEmail}-->" + sysLabel.ShowWebMasterEmail() + "<!--{HL.Config.WebMasterEmail/}-->");
		}
		if (LabelContent.Contains("{HL.Config.SiteUrl}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.SiteUrl}", "<!--{HL.Config.SiteUrl}-->" + sysLabel.ShowSiteUrl() + "<!--{HL.Config.SiteUrl/}-->");
		}
		if (LabelContent.Contains("{HL.Config.PageTitle}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.PageTitle}", "<!--{HL.Config.PageTitle}-->" + sysLabel.ShowPageTitle() + "<!--{HL.Config.PageTitle/}-->");
		}
		if (LabelContent.Contains("{HL.Config.UserCookies}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.UserCookies}", "<!--{HL.Config.UserCookies}-->" + sysLabel.ShowUserCookie() + "<!--{HL.Config.UserCookies/}-->");
		}
		if (LabelContent.Contains("{HL.Config.LogingUserName}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.LogingUserName}", "<!--{HL.Config.LogingUserName}-->" + sysLabel.ShowLogingName() + "<!--{HL.Config.LogingUserName/}-->");
		}
		if (LabelContent.Contains("{HL.Config.LogingUserID}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.LogingUserID}", "<!--{HL.Config.LogingUserID}-->" + sysLabel.ShowLogingUserID() + "<!--{HL.Config.LogingUserID/}-->");
		}
		if (LabelContent.Contains("{HL.Config.TemplateDir}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.TemplateDir}", "<!--{HL.Config.TemplateDir}-->" + sysLabel.GetTemplateDir() + "<!--{HL.Config.TemplateDir/}-->");
		}
		if (LabelContent.Contains("{HL.Config.SkinDir}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.SkinDir}", "<!--{HL.Config.SkinDir}-->" + sysLabel.ProjectSkinDir() + "<!--{HL.Config.SkinDir/}-->");
		}
		if (LabelContent.Contains("{HL.Config.IndexCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.IndexCss}", "<!--{HL.Config.IndexCss}-->" + sysLabel.GetDefaultIndexCss("Index") + "<!--{HL.Config.IndexCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.ShopCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.ShopCss}", "<!--{HL.Config.ShopCss}-->" + sysLabel.GetDefaultIndexCss("Shop") + "<!--{HL.Config.ShopCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.SpecialCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.SpecialCss}", "<!--{HL.Config.SpecialCss}-->" + sysLabel.GetDefaultIndexCss("Special") + "<!--{HL.Config.SpecialCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.ProductCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.ProductCss}", "<!--{HL.Config.ProductCss}-->" + sysLabel.GetDefaultIndexCss("Product") + "<!--{HL.Config.ProductCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.ClassCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.ClassCss}", "<!--{HL.Config.ClassCss}-->" + sysLabel.GetDefaultIndexCss("Class") + "<!--{HL.Config.ClassCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.BasicCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.BasicCss}", "<!--{HL.Config.BasicCss}-->" + sysLabel.GetDefaultIndexCss("Basic") + "<!--{HL.Config.BasicCss/}-->");
		}
		if (LabelContent.Contains("{HL.Config.MemberCss}"))
		{
			LabelContent = LabelContent.Replace("{HL.Config.MemberCss}", "<!--{HL.Config.MemberCss}-->" + sysLabel.GetDefaultIndexCss("Member") + "<!--{HL.Config.MemberCss/}-->");
		}
		LabelContent = this.ReplaceLabel(LabelContent, "HL.Label");
		return LabelContent;
	}
	public string ReplaceLabel(string LabelContent, string LabelName)
	{
		string text = LabelContent;
		string pattern = "{" + LabelName + "(.*?)}";
		MatchCollection matchCollection = Regex.Matches(LabelContent, pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
		string result;
		if (matchCollection.Count > 0)
		{
			foreach (Match match in matchCollection)
			{
				string newValue = "<IMG src=ButtonImage/standard/modeeditbtn.gif alt=" + match.Value.Replace("}", "") + " />";
				text = text.Replace(match.Value, newValue);
			}
			result = this.ReplaceLabel(text, LabelName);
		}
		else
		{
			result = LabelContent;
		}
		return result;
	}
}
